package cn.itcast.testdeadlock;

import cn.itcast.test1.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.test1")
public class test1 {
    public static void main(String[] args) {
        test();
    }
    public static void test(){
        Object objectA = new Object();
        Object objectB = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (objectA){
                log.debug("t1lock A");
                Sleeper.sleep(1);
                synchronized (objectB){
                    log.debug("t1lock B");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (objectB){
                log.debug("t2 lock B");
                Sleeper.sleep(1);
                synchronized (objectA){
                    log.debug("t2 lock A");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
